<?php
class Slash_ACL_Property_SelfPrincipal
extends Slash_ACL_Property_Principal
{
	/*
   * Copyright © 2010 Jack Cleaver
   * 
   * This plugin provides functionality added by CalDAV (RFC 4791)
   * It implements new reports, and the MKCALENDAR method.
   *
   * This file is part of Slash.
   *
   * Slash is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
   * Slash is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with Slash.  If not, see <http://www.gnu.org/licenses/>.
   */
	public function __construct()
	{
	}
	
  public function toString()
  {
  	return "self:";
  }
  
	/*
	 * A self principal includes an href principal if the href of the principal 
	 * is the URI of the referenced node.
	 */
  public function includesPrincipal(Slash_ACL_Property_Principal $princ, Sabre_DAV_FSExt_Node $resourceNode)
	{
		$href = $princ->getHref();
		Slash_Debug::debug("ACL_Property_SelfPrincipal includesPrincipal: I am a self, the principal is " . $princ->toString());
		if ($resourceNode instanceof Slash_ACL_FSExt_Principal)
		{
			$uriNode = new Slash_ACL_FSExt_UriNode($resourceNode);
			$uri = $uriNode->getUri();
			Slash_Debug::debug("ACL_Property_Principal includesPrincipal: target is a principal: $uri");
			return ($href == $uri);
		}			
		return false;
	}
  
	public function serialize(Sabre_DAV_Server $server, DOMElement $node)
	{
		$prefix = $server->xmlNamespaces['DAV:'];
		$doc = $node->ownerDocument;
		$node->appendChild($doc->createElement("$prefix:self"));
	}
  
}
